

package com.hazelcast.internal.metrics;

import com.hazelcast.internal.metrics.impl.MetricsCompressor;

/**
 * Measurement unit of a Probe. Not used on member, becomes a part of the key.
 * <p>
 * <b>NOTE</b>: The enum ordinals are used by {@link MetricsCompressor},
 * therefore, the ordinal values should remain stable between versions to
 * ensure version compatibility.
 * <p>
 * When modifying this enum, please be aware of the following rules
 * <ul>
 *     <li>do not reorder the values of this enum,
 *     <li>do not delete any value from this enum,
 *     <li>add new values at the end of the list,
 *     <li>when introducing a new enum value, mark the value as new by
 *     setting {{@link #newUnit}} to {@code true} and add the version
 *     dependent RU_COMPAT_X_Y.
 * </ul>
 * <p>
 */
public enum ProbeUnit {
    /**
     * Size, counter, represented in bytes
     */
    BYTES,
    /**
     * Timestamp or duration represented in ms
     */
    MS,
    /**
     * Timestamp or duration represented in nanoseconds
     */
    NS,
    /**
     * An integer mostly in range 0..100 or a double mostly in range 0..1
     */
    PERCENT,
    /**
     * Number of items: size, counter...
     */
    COUNT,
    /**
     * 0 or 1
     */
    BOOLEAN,
    /**
     * 0..n, ordinal of an enum
     */
    ENUM,
    /**
     * Timestamp or duration represented in µs
     */
    US;

    /**
     * Setting to {@code true} indicates that when compressing a metric with this
     * unit, the unit should be converted to a tag to ensure backwards compatibility.
     */
    private final boolean newUnit;

    ProbeUnit() {
        this(false);
    }

    ProbeUnit(boolean newUnit) {
        this.newUnit = newUnit;
    }

    public boolean isNewUnit() {
        return newUnit;
    }
}
